﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;

using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Web;

namespace FlightSearchServer
{
    class HostingProgram
    {
        
        static void Main(string[] args)
        {
            if(args.Length < 2){
                Console.WriteLine("Please provide two ports as parameters");
                return;
            }
            string clientsPort = args[0];
            string sellersPort = args[1];

            try
            {

                using (ServiceHost hostClients = new ServiceHost(typeof(FlightSearchServiceClients),
                                                            new Uri("http://localhost:" + clientsPort + "/Services/FlightsSearch")),
                                   hostSellers = new ServiceHost(typeof(FlightSearchServiceSellers),
                                                            new Uri("http://localhost:" + sellersPort + "/Services/FlightsSearchReg")))
                {

                    try
                    {
                        hostClients.Open();
                        hostSellers.Open();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error occured: {0}", e.Message);
                        Console.WriteLine("Can't start service, exiting");
                        return;
                    }
                    Console.WriteLine("Flight search service:         {0} ", "http://localhost:" + clientsPort + "/Services/FlightsSearch");
                    Console.WriteLine("Sellers registration service:  {0} ", "http://localhost:" + sellersPort + "/Services/FlightsSearchReg");
                    Console.WriteLine("FlightSearchServer is running. Press return to exit.");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured: {0}, exiting", e.Message);
            }
        }
    }
}

